/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frxml_get_string_list.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2015/03/24     by geyh                             */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <libxml/xmlreader.h>
#include <libxml/xpath.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>

#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frxml_parse.h"
#include "frmem.h"
#include "frcomm.h"
#include "frlist.h"
#include "conntrack.h"
#include "../../comm/apmtest_cunit.h"
#include "../../comm/apmtest_comm.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static int __list_node_print(Frlist_node *p_st_node, const void *p_data)
{
    Frvar_field *p_var_field = NULL;

    if(p_st_node && p_st_node->data)
    {
        p_var_field = (Frvar_field *)p_st_node->data;
        printf("%s\n",p_var_field->field_value.p_value);
        return 1;
    }

    return 0;
}

static void __my_list_node_free(Frlist_node *p_st_node)
{
    Frvar_field *p_var_field = NULL;

    if(p_st_node && p_st_node->data)
    {
        p_var_field = (Frvar_field *)p_st_node->data;
        if(p_var_field->field_value.p_value)
            frfree(p_var_field->field_value.p_value);
        frfree(p_var_field);
    }

    return;

}

static void __case1(void)
{
    int i_ret = 0;
    char *p_file_name = (char *)"t_frxml_parse/t_frxml_get_string_list/apm_conf.xml";
    char *xpath = (char *)"/apm_frame/apm_timeout";
    char *p_keyword = (char *)"apm_tcp_est_timeout";
    Frlist_header *p_list_header = NULL;

    i_ret = frxml_get_string_list(p_file_name, xpath, p_keyword, &p_list_header);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    frlist_run(p_list_header, NULL, __list_node_print);

    frlist_destroy(p_list_header, __my_list_node_free);
    return;

}

int add_suite_frxml_get_string_list(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm frxml_get_string_list()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);


    return FR_SUCC;
}